package yunquan.wang.modules.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import yunquan.wang.base.dao.MatchType;
import yunquan.wang.base.dao.QueryHelper;
import yunquan.wang.base.dao.springdata.BaseRepository;
import yunquan.wang.base.service.impl.BaseServiceImpl;
import yunquan.wang.modules.base.dao.AuthorityDao;
import yunquan.wang.modules.base.entity.Authority;
import yunquan.wang.modules.base.entity.CodeValue;
import yunquan.wang.modules.base.service.AppCodeService;
import yunquan.wang.modules.base.service.AuthorityService;
/**
 *  Authority Service层 实现
 *  @author 王云权  wangyunquan@gmail.com
 *  用生成器 生成于 2011-09-30 22:37
 *
 */
@Service("authorityService")
@Transactional(value="jpaTransaction")
public class AuthorityServiceImpl extends BaseServiceImpl<Authority>
		implements AuthorityService {
	private AuthorityDao authorityDao;
	@Resource
	 private AppCodeService appCodeService;
	@Resource(name="authorityDao")
	public void setDao(AuthorityDao authorityDao) {
		this.authorityDao = authorityDao;
	}
 
	public BaseRepository<Authority, String> getDao() {
		return authorityDao;
	}

 

	@Override
	public Map<String, List<Authority>> authorityTree() {
		Set<CodeValue> alltypes=	appCodeService.getAllCodeValue("authoritytype");
		Map<String, List<Authority>>  tree=new HashMap<String, List<Authority>> ();
		for(CodeValue type:alltypes)
		{
			List<Authority> auth=		authorityDao.findAll(QueryHelper.filter("authtype", MatchType.EQ, type.getValue()));
			tree.put(type.getValue().toString(), auth);
		}
		
			
		return tree;
	}
	 
}
